#include "../include/statusServe_rpc.h"
#include "../include/conf_reader.h"

statusServer_rpc::statusServer_rpc(){
    //读配置
    endpoint=conf_reader::get_conf_reader_instance()->get_value_from_key("statusServerEndpoint","192.168.174.139:10000");
    _channel=grpc::CreateChannel(endpoint,grpc::InsecureChannelCredentials());
    _stub=message::statusServer::NewStub(_channel);

}

message::resGetChatServerAddress* statusServer_rpc::get_chatServer_address(std::string email)
{
    chat_server_address address;

    grpc::ClientContext context;
    message::reqGetChatServerAddress request;
    message::resGetChatServerAddress* response=new message::resGetChatServerAddress();
    request.set_email(email);
    grpc::Status sts=_stub->get_chatServer_address(&context,request,response);
    if(!sts.ok()){
        
        std::cout<<"！状态服务不在线！"<<std::endl;
        response->set_result(false);
        response->set_info("状态服务不在线");
    }

    return response;


    
}